package com.imooc.trading_system.controller;


import com.imooc.trading_system.service.WalletService;
import com.imooc.trading_system.utils.JsonData;
import com.imooc.trading_system.vo.wallet.DeductionsReqVO;
import com.imooc.trading_system.vo.wallet.TopUpReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Feng zhaoxi
 * @since 2022-05-03
 */
@RestController
@RequestMapping("/api/wallet")
public class WalletController {
    @Autowired
    private WalletService walletService;

    /**
     * 获取钱包信息
     *
     * @return
     */
    @PostMapping("get_wallet_info")
    public JsonData getWalletInfo() {
        return walletService.getWalletInfo();
    }

    /**
     * 充值
     *
     * @return
     */
    @PostMapping("top_up")
    public JsonData topUp(@RequestBody TopUpReqVO topUpReqVO) {
        return walletService.topUp(topUpReqVO);
    }

    /**
     * 扣减、提现
     *
     * @param deductionsReqVO
     * @return
     */
    @PostMapping("deductions")
    public JsonData deductions(@RequestBody DeductionsReqVO deductionsReqVO) {
        int rows = walletService.deductions(deductionsReqVO.getDeductionsValue());
        return JsonData.buildSuccess();
    }

    /**
     * 开启钱包
     *
     * @return
     */
    @PostMapping("open_wallet")
    public JsonData OpenWallet() {
        return walletService.OpenWallet();
    }

    /**
     * 关闭钱包
     *
     * @return
     */
    @PostMapping("close_wallet")
    public JsonData closeWallet() {
        return walletService.closeWallet();
    }
}

